package cn.org.timespace.easyframe.action.permission;

import java.util.List;

import cn.org.timespace.easyframe.OperationLogConst;
import cn.org.timespace.easyframe.action.EFBaseAction;
import cn.org.timespace.easyframe.model.permission.OperationLog;
import cn.org.timespace.easyframe.service.permission.OperationLogService;
import cn.org.timespace.easyframe.util.generator.IdentityGenerator;
import cn.org.timespace.easyframe.util.pager.Pager;
import cn.org.timespace.easyframe.util.pager.PagerHelper;

/**
 * <p>
 * 用户操作日志
 * </p>
 * 
 * @version 1.0, 11/02/11
 * @since 1.0
 * @author 
 */

public class OperationLogAction extends EFBaseAction {

	private static final long serialVersionUID = -3224275471309009166L;
	
	private OperationLogService operationLogService;
	
	// 该构造函数必须这样实现
	public OperationLogAction() {
		super(new OperationLogModel());
	}
	
	/**
	 * 查询用户操作日志
	 * @return
	 * @throws Exception
	 */
	public String doList() throws Exception {
		
		OperationLogModel model = getOperationLogModel();
		Pager p = PagerHelper.getPagerInstance(getRequest());

		List<Object> resList = 
			operationLogService.findByCondition(model,p);
		
		if(resList != null && resList.size() == 2){
			p.setTotalCount(((Integer)resList.get(0)));
			p.setData((List)resList.get(1));
		}
		
		return LIST;

	}
	
	/**
	 * 保存用户操作日志
	 * @return
	 * @throws Exception
	 */
	public String doSave() throws Exception {
		//获取主键
		String operatorId = IdentityGenerator.getInstance().getId();
		
		OperationLog operationLog = new OperationLog();
		operationLog.setOperatorId(operatorId);
		operationLog.setDicModel(OperationLogConst.MODEL_GUESTROOM);  //模块
		operationLog.setDicFunCode(OperationLogConst.FUN_GUESTROOM_YD); //功能代码
		operationLog.setOperationCode(OperationLogConst.OPERATION_CODE_ADD); //操作代码
		operationLog.setContent("开单"); //内容
		operationLog.setEfUser(getCurEfUser());
		operationLog.setOperationDate(getCurDate());
		operationLog.setRemark("测试");
		
		operationLogService.save(operationLog);
		
		return doList();
	}
	
	
	public OperationLogService getOperationLogService() {
		return operationLogService;
	}

	public void setOperationLogService(OperationLogService operationLogService) {
		this.operationLogService = operationLogService;
	}

	private OperationLogModel getOperationLogModel(){
		return (OperationLogModel) this.getModel();
	}
}
